{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "from io import StringIO\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "    \n",
    "\n",
    "def get_hist_numpy(code='600408', start='2017-01-01', end='2017-01-20'):\n",
    "    data = ts.get_hist_data(code, start=start, end=end)\n",
    "    data.to_csv('./123.csv')\n",
    "\n",
    "    df = pd.read_csv('./123.csv',header=None,sep=',') #filename可以直接从盘符开始，标明每一级的文件夹直到csv文件，header=None表示头部为空，sep=' '表示数据间使用空格作为分隔符，如果分隔符是逗号，只需换成 ‘，’即可。\n",
    "    df = df.loc[1:,1:]\n",
    "\n",
    "    data = np.array(df.T)\n",
    "    return (data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if __name__ == '__main__':\n",
    "    print(get_hist_numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_hist_golbal(code='600408', start='2017-01-01', end='2017-01-20'):\n",
    "    data = ts.get_hist_data(code, start=start, end=end)\n",
    "    data.to_csv('./234.csv')\n",
    "\n",
    "    df = pd.read_csv('./234.csv',header=None,sep=',') #filename可以直接从盘符开始，标明每一级的文件夹直到csv文件，header=None表示头部为空，sep=' '表示数据间使用空格作为分隔符，如果分隔符是逗号，只需换成 ‘，’即可。\n",
    "\n",
    "    open_price = df.iloc[-1, 1]\n",
    "    close_price = df.iloc[1, 3]\n",
    "\n",
    "    return (float(close_price)-float(open_price))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['4.53']\n",
      " ['4.7']\n",
      " ['4.82']\n",
      " ['4.83']\n",
      " ['5.07']\n",
      " ['5.05']\n",
      " ['5.12']\n",
      " ['5.2']\n",
      " ['5.12']\n",
      " ['5.03']\n",
      " ['5.25']\n",
      " ['5.29']\n",
      " ['5.28']\n",
      " ['5.29']\n",
      " ['4.69']\n",
      " ['4.7']\n",
      " ['4.84']\n",
      " ['4.89']\n",
      " ['5.14']\n",
      " ['5.2']\n",
      " ['5.17']\n",
      " ['5.23']\n",
      " ['5.25']\n",
      " ['5.22']\n",
      " ['5.28']\n",
      " ['5.37']\n",
      " ['5.36']\n",
      " ['5.42']\n",
      " ['4.64']\n",
      " ['4.53']\n",
      " ['4.73']\n",
      " ['4.84']\n",
      " ['4.83']\n",
      " ['5.14']\n",
      " ['5.05']\n",
      " ['5.14']\n",
      " ['5.19']\n",
      " ['5.12']\n",
      " ['5.22']\n",
      " ['5.25']\n",
      " ['5.29']\n",
      " ['5.31']\n",
      " ['4.48']\n",
      " ['4.44']\n",
      " ['4.72']\n",
      " ['4.69']\n",
      " ['4.63']\n",
      " ['5.01']\n",
      " ['5.0']\n",
      " ['5.11']\n",
      " ['5.12']\n",
      " ['5.03']\n",
      " ['5.14']\n",
      " ['5.25']\n",
      " ['5.23']\n",
      " ['5.19']\n",
      " ['91829.27']\n",
      " ['128508.56']\n",
      " ['65355.0']\n",
      " ['84825.33']\n",
      " ['172523.67']\n",
      " ['114809.28']\n",
      " ['73409.92']\n",
      " ['73074.0']\n",
      " ['102468.56']\n",
      " ['130282.67']\n",
      " ['109977.79']\n",
      " ['83759.03']\n",
      " ['113568.96']\n",
      " ['119403.67']\n",
      " ['0.11']\n",
      " ['-0.2']\n",
      " ['-0.11']\n",
      " ['0.01']\n",
      " ['-0.31']\n",
      " ['0.09']\n",
      " ['-0.09']\n",
      " ['-0.05']\n",
      " ['0.07']\n",
      " ['-0.1']\n",
      " ['-0.03']\n",
      " ['-0.04']\n",
      " ['-0.02']\n",
      " ['0.0']\n",
      " ['2.43']\n",
      " ['-4.23']\n",
      " ['-2.27']\n",
      " ['0.21']\n",
      " ['-6.03']\n",
      " ['1.78']\n",
      " ['-1.75']\n",
      " ['-0.96']\n",
      " ['1.37']\n",
      " ['-1.92']\n",
      " ['-0.57']\n",
      " ['-0.76']\n",
      " ['-0.38']\n",
      " ['0.0']\n",
      " ['4.714']\n",
      " ['4.814']\n",
      " ['4.918']\n",
      " ['5.0']\n",
      " ['5.07']\n",
      " ['5.128']\n",
      " ['5.144']\n",
      " ['5.184']\n",
      " ['5.214']\n",
      " ['5.238']\n",
      " ['5.276']\n",
      " ['5.274']\n",
      " ['5.27']\n",
      " ['5.228']\n",
      " ['4.921']\n",
      " ['4.979']\n",
      " ['5.051']\n",
      " ['5.107']\n",
      " ['5.154']\n",
      " ['5.202']\n",
      " ['5.209']\n",
      " ['5.227']\n",
      " ['5.221']\n",
      " ['5.205']\n",
      " ['5.188']\n",
      " ['5.173']\n",
      " ['5.158']\n",
      " ['5.137']\n",
      " ['5.055']\n",
      " ['5.076']\n",
      " ['5.105']\n",
      " ['5.122']\n",
      " ['5.142']\n",
      " ['5.164']\n",
      " ['5.169']\n",
      " ['5.167']\n",
      " ['5.163']\n",
      " ['5.164']\n",
      " ['5.191']\n",
      " ['5.207']\n",
      " ['5.223']\n",
      " ['5.236']\n",
      " ['108608.37']\n",
      " ['113204.37']\n",
      " ['102184.64']\n",
      " ['103728.44']\n",
      " ['107257.09']\n",
      " ['98808.89']\n",
      " ['97842.59']\n",
      " ['99912.41']\n",
      " ['108011.4']\n",
      " ['111398.42']\n",
      " ['104628.32']\n",
      " ['104537.21']\n",
      " ['129308.29']\n",
      " ['133811.37']\n",
      " ['103708.63']\n",
      " ['105523.48']\n",
      " ['101048.53']\n",
      " ['105869.92']\n",
      " ['109327.76']\n",
      " ['101718.6']\n",
      " ['101189.9']\n",
      " ['114610.35']\n",
      " ['120911.39']\n",
      " ['119916.41']\n",
      " ['118294.6']\n",
      " ['115692.53']\n",
      " ['116856.87']\n",
      " ['120991.72']\n",
      " ['111001.61']\n",
      " ['110608.01']\n",
      " ['108952.7']\n",
      " ['113430.82']\n",
      " ['113609.27']\n",
      " ['110781.0']\n",
      " ['115231.66']\n",
      " ['117901.95']\n",
      " ['126747.9']\n",
      " ['131486.55']\n",
      " ['132740.62']\n",
      " ['135281.63']\n",
      " ['137072.55']\n",
      " ['138575.88']\n",
      " ['0.91']\n",
      " ['1.28']\n",
      " ['0.65']\n",
      " ['0.84']\n",
      " ['1.71']\n",
      " ['1.14']\n",
      " ['0.73']\n",
      " ['0.73']\n",
      " ['1.02']\n",
      " ['1.29']\n",
      " ['1.09']\n",
      " ['0.83']\n",
      " ['1.13']\n",
      " ['1.19']]\n"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "#     print(get_hist_numpy())\n",
    "#     print(get_hist_golbal())\n",
    "    ghn = get_hist_numpy()\n",
    "    ghn = ghn.reshape(-1, 1)\n",
    "    print(ghn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    ""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
